package de.playmee.views;

import de.playmee.R;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProgressBarHorizontalView extends LinearLayout {
	
	private int max;
	private ProgressBar progressBar;
	private TextView titleView;
	private TextView percentageView;
	private TextView progressView;

	public ProgressBarHorizontalView(Context context, int max) {
		super(context);
		this.max = max;
		
		setOrientation(VERTICAL);
		setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.progressbar_horizontal, this);
		
		// title, percentage, progress
		titleView = (TextView) findViewById(R.id.progressBarHorizontalTitle);
		percentageView = (TextView) findViewById(R.id.progressBarHorizontalPercentage);
		progressView = (TextView) findViewById(R.id.progressBarHorizontalProgress);
		
		// progressBar
		progressBar = (ProgressBar) findViewById(R.id.progressBarHorizontal);
		progressBar.setMax(max);
		// TODO color
	}
	
	/**
	 * sets the title
	 * 
	 * @param title
	 */
	public void setTitle(String title) {
		titleView.setText(title);
	}
	
	/**
	 * sets the progress
	 * 
	 * @param progress
	 */
	public void setProgress(int progress) {
		progressBar.setProgress(progress);
		progressView.setText(progress + "/" + max);
		double p = ((double) progress) / max * 100;
		percentageView.setText(Math.round(p) + "%");
	}
}
